package com.song.orderservice.service.impl;

import com.song.cmsservice.client.IndexFeign;
import com.song.cmsservice.entity.UcenterMember;
import com.song.cmsservice.service.UcenterMemberService;
import com.song.commonutils.ResultObj;
import com.song.commonutils.ordervo.CourseWebVoOrder;
import com.song.commonutils.ordervo.UcenterMemberOrder;
import com.song.orderservice.entity.TOrder;
import com.song.orderservice.mapper.TOrderMapper;
import com.song.orderservice.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.song.orderservice.utils.OrderNoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author song
 * @since 2020-04-06
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Autowired
    private UcenterMemberService ucenterMemberService;

    @Autowired
    private IndexFeign indexFeign;


    @Override
    public String createOrders(String courseId, String id) {

        //获取用户信息
        UcenterMember ucenterMember = ucenterMemberService.getById(id);
        //获取课程信息
        CourseWebVoOrder courseInfo = indexFeign.getCourseInfoOrder(courseId);
        TOrder order=new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());//订单号

        order.setCourseId(courseId); //课程id
        order.setCourseTitle(courseInfo.getTitle());
        order.setCourseCover(courseInfo.getCover());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setMemberId(id);
        order.setMobile(ucenterMember.getMobile());
        order.setNickname(ucenterMember.getNickname());
        order.setStatus(0);  //订单状态（0：未支付 1：已支付）
        order.setPayType(1);  //支付类型 ，微信1

        baseMapper.insert(order);
        //返回订单号
        return order.getOrderNo();
    }


}
